package calorie.com.calorie.contact;

import android.content.Context;
import android.util.Log;

import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;

import calorie.com.calorie.api.ApiService;
import calorie.com.calorie.request.BuyGoodsRequest;
import calorie.com.calorie.response.BuyGoodsResponce;
import retrofit2.Call;
import retrofit2.Response;

/**
 * Created by chenxi on 2019/4/10.
 */

public class BuyGoodsContact {
    public static class BuyGoodsPresent extends BasePresent<IBuyGoodsView> {
        public void buyGoods(final Context context, Integer userId, String dealPassword, String goodsId,Integer count,String goodsAttribute){
            ApiService service = ServiceGenerator.createService(ApiService.class);
            BuyGoodsRequest request = new BuyGoodsRequest(userId,dealPassword,goodsId,count,goodsAttribute);
            service.buyGoods(request).enqueue(new NetCallBack<BuyGoodsResponce>() {
                @Override
                public void onSuccess(Call<BuyGoodsResponce> call, Response<BuyGoodsResponce> response) {
                    if(getView()!= null){
                        getView().getBuyGoodsResult(response);
                    }
                }

                @Override
                public void onFailed() {
                    Log.e("aaa","some wrong");
                }
            });
        }
    }

    public interface IBuyGoodsView extends IBaseView {
        void getBuyGoodsResult(Response<BuyGoodsResponce> response);
    }
}
